﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Model;

namespace DALayer
{
    public class UserInfoDAL
    {
        /// <summary>
        /// 检索用户是否以注册
        /// </summary>
        /// <param name="Phone">手机号</param>
        /// <returns></returns>
        public static Boolean SelectUser(string Phone)
        {
            string sql = $"select * from UserInfo where UserID='{Phone}'";
            return DBHelper.SelectByAdapter(sql).Rows.Count>0;
        }

        /// <summary>
        /// 检索用户是否存在
        /// </summary>
        /// <param name="UserPhone">用户手机</param>
        /// <param name="UserPwd">用户密码</param>
        /// <returns></returns>
        public static DataTable SelectUser(string UserPhone, string UserPwd)
        {
            string sql = $"select * from UserInfo where UserID='{UserPhone}' and UserPwd='{UserPwd}'";
            return DBHelper.SelectByAdapter(sql);
        }

        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="us">用户对象</param>
        /// <returns>返回值真假</returns>
        public static Boolean InserUserInfo(UserModel us)
        {
            string sql = $"insert into UserInfo(UserID,UserName,UserPwd) values('{us.UserID}','{us.UserName}','{us.UserPwd}')";
            return DBHelper.UTNonQuery(sql) > 0;
        }

        
    }

}
